package com.woniuxy.consumer.service.impl;

import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.entity.UserDetails;
import com.woniuxy.commons.entity.Userinfo;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.commons.utils.ResultStatus;
import com.woniuxy.consumer.mapper.UserdetailsMapper;
import com.woniuxy.consumer.mapper.UserinfoMapper;
import com.woniuxy.consumer.service.UserinfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-12 18:15
 */
@Service
public class ServiceImpl implements UserinfoService {
    @Resource
    private UserinfoMapper userinfoMapper;

    @Resource
    private UserdetailsMapper userdetailsMapper;


    @Override
    public void insertUserinfoService(Userinfo userinfo) {

    }

    @Override
    public ResponseResult<PageBean<Userinfo>> selectUserinfoByPageService(UserDetails userDetails,
                                                                          int pageIndex, int pageSize) {
        PageBean<Userinfo> pageBean = new PageBean<>();
        List<Userinfo> userinfos = userinfoMapper.selectUserinfoByPage(userDetails, pageIndex, pageSize);
        //得到表中数据总条数
        int i = userdetailsMapper.selectCountUserDetailsByPage(userDetails);

        pageBean.setBeanList(userinfos);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);
        ResponseResult<PageBean<Userinfo>> result = new ResponseResult<>();
        result.setCode(200);
        result.setMessage("成功");
        result.setStatus(ResultStatus.SELECT_YES);
        result.setData(pageBean);
        return result;
    }


    @Override
    public ResponseResult deleteByUid(String uid) {

        if(userinfoMapper.deleteByUid(uid) && userdetailsMapper.deleteByUid(uid)){
            return new ResponseResult(200, ResultStatus.SELECT_YES, "成功", "");
        }
        return new ResponseResult(252, ResultStatus.NO_PERMS, "失败", "");
    }



}
